package com.korubo.web.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.korubo.kit.R;
import com.korubo.web.model.Carousel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.korubo.web.mapper.OrderMapper;
import com.korubo.web.model.Order;
import com.korubo.web.service.OrderService;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public R list(Order order) {
        QueryWrapper<Order> query = new QueryWrapper<>();

        if (StrUtil.isNotEmpty(order.getName())) {
            query.like("name", order.getName());
        }
        if (StrUtil.isNotEmpty(order.getStatus())) {
            query.eq("status", order.getStatus());
        }
        if (StrUtil.isNotEmpty(order.getType())) {
            query.eq("type", order.getType());
        }
        //排序时间
        query.orderByDesc("create_time");
        Page<Order> orderPage = orderMapper.selectPage(new Page<>(order.getPageNum(), order.getPageSize()), query);
        return R.ok(orderPage);
    }

    @Override
    public R orders() {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        List<Order> carousels = orderMapper.selectList(queryWrapper);
        return R.ok(carousels);
    }
}
